<?php
// DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
//header items
$jQuery = true;
$tinyMCE = true;
$jQueryCookie = true;
$hoverIntent = true;
$Jededitable = true;
$sectionSort = true;
$googleAPI = false;
$calendar = false;
//end header items
$pageTitle = 'Soberpress - Administration - Home Modules';
require_once ('../../config/include_paths.php');
require_once('config.php');
require_once('functions.php');
require_once('dbconnect.php');	// database connect script.
$page_id = 1; //home=1 contacts=4
$table = 'users'; //set appropriate table
session_start();

if ($_SESSION['logged_in'] == 0) {
	require ('security_check.php');
} else {
require_once ('adminhead.php');
if ($_POST) {
	if ($_POST['password'])	{
		$_POST['password'] =  hash('md5', $_POST['password']);
	}
  		processTable('users');
		$message = $_SESSION['message'];
}
if (isset($_GET['id'])) {
		$whereClause = 'WHERE id ="'.$_GET['id'].'"';
	}elseif (isset($_POST['id'])) {
		$whereClause = 'WHERE id ="'.$_POST['id'].'"';
	}else{
		$whereClause = 'WHERE username = "'.$_SESSION['username'].'"';
		}
$sql= "SELECT * FROM users ".$whereClause;
	$result = mysql_query($sql,$conn);
	while($row = mysql_fetch_array($result))
	  {
	  $id = $row['id'];
	  $username = $row['username'];
	  $password = $row['password'];
	  $fname = $row['fname'];
	  $lname = $row['lname'];
	  $title = $row['title'];
	  $email = $row['email'];
	  $admin = $row['admin'];
	  $listInContacts = $row['listInContacts'];
	  
	  }
	  if ($admin == '1') {$adminYes = 'checked = "checked"';}else{$adminNo = 'checked = "checked"';}
	  if ($listInContacts == '1') {$listInContactsYes = 'checked = "checked"';}else{$listInContactsNo = 'checked = "checked"';}
?>
<body onLoad="checkMenuSettings();">
<script language="javascript" type="text/javascript">
var table = '<?php echo $table ?>';
var message = '<?php echo $message ?>';
var selectPass = function() {
		$('#passwordContainer').html('<input type="password" name="password" id="password">');
		$('#password').focus().select();
	};
$(document).ready(function() {
	$('#password').attr('readonly', true);
	$('#password').focus(function () {
		if (confirm("Do you want to change the password?")) {
			$('#password').attr('readonly', false);
			$('#password').unbind();
			selectPass();
		}else{
			//do nothing
			};
		});

});
</script>
<div id="wrapper">
  <?php require_once ('adminHeader.php'); ?>
  <div class="clearfloat">&nbsp;</div>
  <div id="sidebar">
    <?php require_once ('adminNav.php'); ?>
  </div>
  <div id="main_content">
  
  	<form name="userform" method="post" action="userform.php">
  	<table id = "userInput" width="600px" border="0" cellspacing="5" cellpadding="5">
 	<tr><th colspan="2">User Information</th></tr>
      <tr>
  	    <td><label for="username">User Name</label></td>
  	    <td><input type="text" name="username" id="username" value="<? echo $username ?>"></td>
      </tr>
  	  <tr>
  	    <td><label for="password">Password</label></td>
  	    <td><span id="passwordContainer"><input type="password" name="junk" id="password" value="<? echo $username ?>"></span></td>
      </tr>
  	  <tr>
  	    <td><label for="fname">First Name</label></td>
  	    <td><input type="text" name="fname" id="fname" value="<? echo $fname ?>"></td>
      </tr>
  	  <tr>
  	    <td><label for="lname">Last Name</label></td>
  	    <td><input type="text" name="lname" id="lname" value="<? echo $lname ?>"></td>
      </tr>
  	   <tr>
  	    <td><label for="title">Title</label></td>
  	    <td><input type="text" name="title" id="title" value="<? echo $title ?>"></td>
      </tr>
  	  <tr>
  	    <td><label for="email">EMail</label></td>
  	    <td><input type="text" name="email" id="email" value="<? echo $email ?>"></td>
      </tr>
      <tr class="radioInputs">
          <td><label for="admin">Admin</label></td>
          <td><p>
            <label>
              <input type="radio" name="admin" value="1" <?php echo $adminYes ?>  id="Admin_0">
              Yes</label>
            <label>
              <input type="radio" name="admin" value="0" <?php echo $adminNo ?> id="Admin_1">
              No</label>
            <br>
          </p>
        </td>
      </tr>
       <tr class="radioInputs">
          <td><label for="listInContacts">List in Contacts</label></td>
          <td><p>
            <label>
              <input type="radio" name="listInContacts" value="1" <?php echo $listInContactsYes ?> id="listInContacts_0">
              Yes</label>
            <label>
              <input type="radio" name="listInContacts" value="0" <?php echo $listInContactsNo ?> id="listInContacts_1">
              No</label>
            <br>
          </p>
        </td>
      </tr>
      <tr>
  	    <td colspan="2"><input type="submit" id="sp_submit" name="submit" value="Submit" class="groovybutton">
        <input type="button" value="Cancel" class="groovybutton" onClick="history.back()"></td>
      </tr>
    </table>
    <input type="hidden" name="id" value="<? echo $id ?>">
    </form>
    <div id="message"></div>
  </div>
</div>
<?php mysql_close($conn);
} ?>

</body>
</html>